package com.hrsoft.edi.stub;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.hrsoft.edi.stub.consant.AppInfo;
import com.hrsoft.edi.stub.request.StockoutCreateRequest;
import com.qimen.api.DefaultQimenClient;
import com.qimen.api.QimenClient;
import com.qimen.api.response.StockoutCreateResponse;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @ClassName StockOutCreateTest
 * @Author huyka
 * @Date 2019/5/30 16:58
 * @Description
 */
@Slf4j
public class StockOutCreateTest {

    public static void create()
            throws ApiException
    {
        QimenClient client = new DefaultQimenClient(AppInfo.URL, AppInfo.APP_KEY, AppInfo.SECRET);
        StockoutCreateRequest createRequest = new StockoutCreateRequest();
        createRequest.setCustomerId(AppInfo.CUSTOMER_ID);
        createRequest.setVersion("2.0");
        StockoutCreateRequest.DeliveryOrder deliveryOrder = new StockoutCreateRequest.DeliveryOrder();
        deliveryOrder.setWarehouseCode(AppInfo.WAREHOUSE_CODE);
        deliveryOrder.setLogisticsCode("SF");
        deliveryOrder.setDeliveryOrderCode("DZL2B" + RandomUtil.randomNumbers(8));
        deliveryOrder.setOrderType("PTCK");
        deliveryOrder.setSourcePlatformCode("TB");
        deliveryOrder.setSourcePlatformName("淘宝");
        deliveryOrder.setCreateTime(DateUtil.formatDateTime(new Date()));
        deliveryOrder.setPlaceOrderTime(DateUtil.formatDateTime(new Date()));
        deliveryOrder.setOperateTime(DateUtil.formatDateTime(new Date()));
        //deliveryOrder.setShopNick("小风扇淘宝旗舰店");
        StockoutCreateRequest.SenderInfo senderInfo = new StockoutCreateRequest.SenderInfo();
        senderInfo.setName("胡胡胡");
        senderInfo.setMobile("13887898786");
        senderInfo.setProvince("浙江省");
        senderInfo.setCity("杭州市");
        senderInfo.setDetailAddress("西湖大街");
        StockoutCreateRequest.ReceiverInfo receiverInfo = new StockoutCreateRequest.ReceiverInfo();
        receiverInfo.setName("张三");
        receiverInfo.setMobile("13887898786");
        receiverInfo.setProvince("浙江省");
        receiverInfo.setCity("杭州市");
        receiverInfo.setDetailAddress("西湖大街123号2栋202");
        deliveryOrder.setReceiverInfo(receiverInfo);
        deliveryOrder.setSenderInfo(senderInfo);
        createRequest.setDeliveryOrder(deliveryOrder);
        List<StockoutCreateRequest.OrderLine> orderLines = new ArrayList<>();
        createRequest.setOrderLines(orderLines);
        StockoutCreateRequest.OrderLine orderLine = new StockoutCreateRequest.OrderLine();
        orderLine.setItemCode("0001");
        orderLine.setPlanQty("2");
        orderLine.setActualPrice("1");
        orderLine.setInventoryType("ZP");
        orderLine.setOwnerCode(AppInfo.OWNER_CODE);
        orderLines.add(orderLine);
        long time1 = System.currentTimeMillis();
        StockoutCreateResponse response = client.execute(createRequest);
        long time2 = System.currentTimeMillis();
        log.info("响应:{} ERP订单编码:{} wms仓储编码:{} 耗时:{}",response.getFlag(),deliveryOrder.getDeliveryOrderCode(),response.getDeliveryOrderId(),time2-time1);
    }

    public static void main(String[] args)
            throws ApiException
    {
        create();
//        for (int i = 0; i < 10000; i++)
//        {
//            create();
//        }
    }
}
